package com.zy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.mapper.StaffMapper;
import com.zy.pojo.Staff;
import com.zy.service.StaffService;
import com.zy.vo.ManagementVo;
import com.zy.vo.ResultVo;
import com.zy.vo.StaffVo.StaffVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.List;

@Service("staffService")
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
    @Resource
    private StaffMapper staffMapper;
    @Override
    public StaffVo getPage(Integer pageNo, Integer pageSize, ManagementVo managementVo) {
        Page page =new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(managementVo.getUserCode()),"user_code",managementVo.getUserCode())
                .eq(managementVo.getUserRole()!=null,"user_role",managementVo.getUserRole());
        List<Staff> list =staffMapper.getUserList(page,queryWrapper);

        return new StaffVo(list,page.getTotal());
    }


    @Override
    public Staff getUserCode(String userCode) {
        LambdaQueryWrapper<Staff> lambdaQueryWrapper =new LambdaQueryWrapper<>();
       lambdaQueryWrapper.eq(Staff::getUserCode,userCode);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public void add(Staff staff) {
        staffMapper.insert(staff);
    }


    @Override
    public void update(Staff staff) {
        staffMapper.updateById(staff);
    }

    @Override
    public void del(Integer id) {
        staffMapper.deleteById(id);
    }

    @Override
    public void err(Integer id) {
        staffMapper.selectById(id);
    }

    @Override
    public Staff login(String userCode, String password) {

        return staffMapper.login(userCode,password);
    }


}
